<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<h1>选课页面</h1>
<div id="check-box">

</div>
<div>
    <button type="button" class="btn btn-default">确认</button>
</div>
</body>
<script>
    $(function (){

        $("button").click(function(){
            var chk_value =[];
            $('input:checkbox').each(function() {
                if ($(this).prop('checked') ==true) {
                    chk_value.push($(this).val());
                }
            });
            console.log(chk_value);

            $.ajax({
                url:"/setResult",
                type:"post",
                contentType:"application/json",
                data:JSON.stringify(chk_value),
                success:function (res){
                    console.log(res)
                    window.location.href="/result.html"
                }
            })
        });

        $.ajax({
            url:"/getKecheng",
            type:"get",
            success:function (res){
                console.log(res)
                var checks = "";
                $.each(res,function(n,value) {
                    //alert(n+' '+value);

                    checks += '<input type="checkbox" name="kecheng" value="'+value+'" />'+value;
                });

                $("#check-box").append(checks);
            }
        })
    })
</script>
</html>